<template>
	<view class="tabbar_area_fixed">
		<view class="tabbar_middle">
			<image class="tabbar_bg" src="/static/tabbar/tabbar_bg.png" mode="aspectFill"></image>
		</view>
		<view class="tabbar_area">
			<view @click="tabbarChange('0')" class="tabbar_item">
				<image v-if="tabbarIndex === '0'" src="/static/tabbar/tabbar_hl_0.png" class="tabbar_icon"></image>
				<image v-else src="/static/tabbar/tabbar_0.png" class="tabbar_icon"></image>
				<view class="tabbar_text" :class="{ active: tabbarIndex === '0' }">首页</view>
			</view>
			<view @click="tabbarChange('1')" class="tabbar_item middle">
				<image src="/static/tabbar/middle.png" class="tabbar_icon_middle"></image>
				<view class="tabbar_text" :class="{ active: tabbarIndex === '1' }">文交财经</view>
			</view>
			<view @click="tabbarChange('2')" class="tabbar_item">
				<image v-if="tabbarIndex === '2'" src="/static/tabbar/tabbar_hl_2.png" class="tabbar_icon"></image>
				<image v-else src="/static/tabbar/tabbar_2.png" class="tabbar_icon"></image>
				<view class="tabbar_text" :class="{ active: tabbarIndex === '2' }">个人中心</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	name: 'tabbar-com',
	data() {
		return {};
	},
	computed: {
		...mapGetters(['tabbarIndex'])
	},
	methods: {
		tabbarChange(index) {
			let obj = {
				'0': '/pages/tabbar/home/home',
				'1': '/pages/tabbar/news/news',
				'2': '/pages/tabbar/my/my'
			};
			let url = obj[index];
			this.$store.commit('setTabbarIndex', index);
			uni.switchTab({ url });
		}
	}
};
</script>

<style lang="scss">
.tabbar_area_fixed {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	padding-bottom: 0;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	background: #ffffff;
}
.tabbar_area {
	display: flex;
	justify-content: space-around;
	align-items: center;
	height: 100rpx;
	z-index: 999;

	.tabbar_icon {
		width: 48rpx;
		height: 48rpx;
	}
	.tabbar_icon_middle {
		width: 96rpx;
		height: 96rpx;
	}
	.tabbar_text {
		font-size: 20rpx;
		color: #c7cad1;
		font-weight: bold;
	}
	.tabbar_item {
		width: 33.33%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 10rpx 0;
	}
	.tabbar_item.middle {
		margin-top: -48rpx;
	}
	.tabbar_text.active {
		color: #0e0e0f;
	}
}

.tabbar_middle {
	width: 100%;
	height: 158rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	position: fixed;
	left: 0;
	bottom: 0;
	z-index: -1;
	pointer-events: none;
	padding-bottom: 0;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
}
.tabbar_bg {
	width: 100%;
	height: 158rpx;
}
</style>
